<template>
	<div class="gk-layout-container">
		<!--工具栏-->
		<div class="gk-layout-header">
			<s-query perms="do:obatch" @click="findPage" add=true @addClick="handleAdd">
				<el-form-item>
					<el-input v-model="filters.doNo" placeholder="出厂单号" :style="{ width: '155px' }"></el-input>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.direction" placeholder="去向" :style="{ width: '145px' }"></el-input>
				</el-form-item>
				<s-dict name="doStatus" v-model="filters.status"> </s-dict>
				<s-date @dateChange="function (v) { filters.createBeginTime = v }" placeholder="开始时间" />
				<s-date @dateChange="function (v) { filters.createEndTime = v }" placeholder="结束时间" />
			</s-query>

			<s-reflash reflash="true" @findPage="findPage"> </s-reflash>

		</div>
		<div class="gk-layout-main">
			<el-table :data="pageResult.content" class='gk-main-table' height="250" v-loading="loading" size="mini"
				align="left" style="width:100%;">
				<el-table-column :label="$t('action.desc')" width="50" header-align="center" align="center">
					<template slot-scope="scope"> {{ scope.$index + 1 }} </template>
				</el-table-column>
				<column prop="doNo" label="出厂单号" />
				<column prop="direction" label="去向" />
				<column prop="status" label="状态" :formatter="selectionFormat" />
				<column prop="beginTime" :label="$t('beginTime')" :formatter="dateFormat" />
				<column prop="finshTime" :label="$t('finshTime')" :formatter="OverdateFormat" />

				<el-table-column width="250" header-align="center" align="center" v-if='true'
					:label="$t('action.operation')">
					<template slot-scope="scope">
						<kt-delete-button v-if="true" perms="doo:item:delete"
							@click="handleDelete(scope.$index, scope.row)" />
						<kt-button label="编辑" perms="do:obatch:edit" @click="handleEdit(scope.$index, scope.row)" />
						<kt-button v-if="true" icon="fa fa-edit" label="生成任务" perms="do:obatch:edit"
							@click="handleGenerate(scope.$index, scope.row)" />
					</template>
				</el-table-column>


			</el-table>
		</div>
		<!--分页栏-->
		<div class="toolbar gk-layout-footer" style="padding:10px;">
			<kt-button :label="$t('action.batchDelete')" v-if="false" perms="doo:batch:permsDelete" :size="global.gSize"
				type="danger" @click="handleBatchDelete()" disabled="false" style="float:left;" />
			<el-pagination layout="total, prev, pager, next, jumper" @current-change="findPage"
				:current-page="filters.pageNum" :page-size="filters.pageSize" :total="pageResult.totalSize"
				style="float:right;">
			</el-pagination>
		</div>






		<doo-batch :key="componentKey" :subDataForm="dataForm" :dialogVisible="dialogVisible1" :operation="operation"
			@receiptHidden="receiptHidden"></doo-batch>

	</div>
</template>

<script>


import KtButton from "@/views/Core/KtButton"
import SDate from "@/components/Kj/SDate"
import SQuery from "@/components/Kj/SQuery"
import SReflash from "@/components/Kj/SReflash"
import { format } from "@/utils/datetime"
import DooBatch from "./DooBatch"
import SDict from "@/components/Kj/SDict"
import Column from "@/views/Core/Column"
import KtDeleteButton from "@/views/Core/KtDeleteButton"
import { dictsFormat } from "@/utils/myUtil"
export default {
	components: {
		SDate,
		SQuery,
		KtButton,
		DooBatch,
		KtDeleteButton,
		Column, SReflash, SDict
	},
	data() {
		return {
			size: 'small',
			loading: false,
			filters: {
				batchNo: '',
				outType: 1000,
				outTypeClass: 0, pageNum: 1, pageSize: 7
			},
			componentKey: 0,
			pageResult: {},

			operation: false, // true:新增, false:编辑
			dialogVisible1: false, // 新增编辑界面是否显示
			editLoading: false,

			// 新增编辑界面数据
			dataForm: {
				id: 0,
				outTypeClass: 3,
				outType: parseInt(this.$route.path.substr(this.$route.path.lastIndexOf('/') + 1))
			},
			deptData: [],
			 
			roles: []
		}
	},
	computed: {

	},
	methods: {
		receiptHidden: function () {

			this.dialogVisible1 = false;
			this.findPage(-1);
		},
		// 获取分页数据
		findPage: function (data) {
			if (data != -1) {
				this.filters.pageNum = data
			}

			this.$api.doo.findPage(this.filters).then((res) => {
				this.pageResult = res.data
				console.log(this.pageResult.content.status);
			})
		},

		// 批量删除
		handleDelete: function (index, data) {
			let params = [{ 'id': data.id }]
			this.$api.doo.batchDelete(params).then((res) => {
				if (res.code == 200) {
					this.$message({ message: '操作成功', type: 'success' })
					this.findPage(this.filters.pageNum)
				} else {
					this.$message({ message: '操作失败, ' + res.msg, type: 'error' })
				}
			})
		},
		// 显示新增界面
		handleAdd: function () {
			this.componentKey += 1;
			this.dialogVisible1 = true
			this.operation = true
			this.dataForm = {
				id: 0,
				outTypeClass: 3,
				outType: parseInt(this.$route.path.substr(this.$route.path.lastIndexOf('/') + 1))
			}
		},
		OverdateFormat: function (row, column, cellValue, index) {

			if (row.status == 3) {
				return format(row[column.property]);
			}
			else {
				return "";
			}

		},
		// 显示编辑界面
		handleEdit: function (params, row) {

			this.dataForm = Object.assign({}, row)
			this.dialogVisible1 = true
			this.operation = true
		},


		// 时间格式化
		dateFormat: function (row, column, cellValue, index) {
			return format(row[column.property])
		},
		selectionFormat: function (row, column, cellValue, index) {
			return dictsFormat("doStatus", cellValue)
		},

		// 生成任务
		handleGenerate: function (params) {
			this.$confirm('确定生成任务吗？', '提示', {}).then(() => {
				this.$api.doo.batchoutGenerate(params.row).then((res) => {
					if (res.code == 200) {
						this.$message({ message: '操作成功', type: 'success' })
						this.findPage(-1)
					} else {
						this.$message({ message: '操作失败, ' + res.msg, type: 'error' })
					}
				})
			})
		},

		// 处理表格列过滤显示

	},
	created() {


	},
	mounted() {
		this.findPage(1)
	},
	watch: {
		$route(to, from) {
			console.log(to.path);

			this.filters.outType = parseInt(to.path.substr(to.path.lastIndexOf('/') + 1))
			this.findPage(1);
		}
	}
}
</script>

